<!DOCTYPE html><html><head><meta charset="utf-8"><style>body {
  max-width: 980px;
  border: 1px solid #ddd;
  outline: 1300px solid #fff;
  margin: 16px auto;
}

body .markdown-body
{
  padding: 45px;
}

@font-face {
  font-family: fontawesome-mini;
  src: url(data:font/woff;charset=utf-8;base64,d09GRgABAAAAABE0AA8AAAAAHWwAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABWAAAADsAAABUIIslek9TLzIAAAGUAAAAQwAAAFY3d1HZY21hcAAAAdgAAACqAAACOvWLi0FjdnQgAAAChAAAABMAAAAgBtX/BGZwZ20AAAKYAAAFkAAAC3CKkZBZZ2FzcAAACCgAAAAIAAAACAAAABBnbHlmAAAIMAAABdQAAAjkYT9TNWhlYWQAAA4EAAAAMwAAADYQ6WvNaGhlYQAADjgAAAAfAAAAJAc6A1pobXR4AAAOWAAAACAAAAA0Kmz/7mxvY2EAAA54AAAAHAAAABwQPBJubWF4cAAADpQAAAAgAAAAIAEHC/NuYW1lAAAOtAAAAYQAAALxhQT4h3Bvc3QAABA4AAAAfgAAAMS3SYh9cHJlcAAAELgAAAB6AAAAhuVBK7x4nGNgZGBg4GIwYLBjYHJx8wlh4MtJLMljkGJgYYAAkDwymzEnMz2RgQPGA8qxgGkOIGaDiAIAJjsFSAB4nGNgZHZmnMDAysDAVMW0h4GBoQdCMz5gMGRkAooysDIzYAUBaa4pDA4Pwz+yMwf9z2KIYg5imAYUZgTJAQDcoQvQAHic7ZHNDYJAFIRnBXf94cDRIiyCKkCpwFCPJ092RcKNDoYKcN4+EmMPvpdvk539zQyAPYBCXEUJhBcCrJ5SQ9YLnLJe4qF5rdb+uWPDngNHTkta101pNyWa8lMhn6xx2dqUnW4q9YOIhAOOeueMSgsR/6ry+P7O5s6xVNg4chBsHUuFnWNJ8uZYwrw7chrsHXkODo7cB0dHOYCTY8kv0VE2WJKD6gOlWjsxAAB4nGNgQAMSEMgc9D8LhAESbAPdAHicrVZpd9NGFB15SZyELCULLWphxMRpsEYmb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Sn53XMPE+3Bcx4P3M9DrvYmWoRWNQVN02kFXTPdCU4pSGQu5saE2meiLhU6timPtz3SSs9ypTCdqrJabWJoT5QQnymSRTkXgt0/UkUqVkVbN807ZdtmxdiEWRidi6HqItdErNbN+aO2612qd9sYAGmvsYRBhyUu0EGhQbfK/gzYCdElTOgSdB1eEFBIxFYkNV4RFJWPeZyyYpVQVHTHZx4y/yVGX2LGWFZri51TccUOn5B7nPefVCSPvGhVVwUl9znveO2KkhV8Wk82PZ8qwZf8OVcu1+fSmWCMw/HMOwXvKaysqM+p+cVuWag8tvv+c+xdd+4+teJxtjUEOwiAURJla24KliQfhUA2g/Sl+CKXx+loNrpzVezOLEY34Ron/0WhwQoszOvQYIKFwwQiNSbSBeO2SZ0tBP4j3zVjKNng32ZmtD1VVXCuOiw/pJ8S3WOU6l+K5UOTaDC4+2TjKMtN9KQf1ezLx/Sg/00FCvABHhjDjAAB4nGPw3sFwIihiIyNjX+QGxp0cDBwMyQUbGVidNjEwMmiBGJu5mBg5ICw+BjCLzWkX0wGgNCeQze60i8EBwmZmcNmowtgRGLHBoSNiI3OKy0Y1EG8XRwMDI4tDR3JIBEhJJBBs5mFi5NHawfi/dQNL70YmBhcADHYj9AAA) format('woff');
}

.markdown-body {
  font-family: sans-serif;
  -ms-text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  color: #333333;
  overflow: hidden;
  font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  word-wrap: break-word;
}

.markdown-body a {
  background: transparent;
}

.markdown-body a:active,
.markdown-body a:hover {
  outline: 0;
}

.markdown-body b,
.markdown-body strong {
  font-weight: bold;
}

.markdown-body mark {
  background: #ff0;
  color: #000;
  font-style: italic;
  font-weight: bold;
}

.markdown-body sub,
.markdown-body sup {
  font-size: 75%;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}
.markdown-body sup {
  top: -0.5em;
}
.markdown-body sub {
  bottom: -0.25em;
}

.markdown-body h1 {
  font-size: 2em;
  margin: 0.67em 0;
}

.markdown-body img {
  border: 0;
}

.markdown-body hr {
  -moz-box-sizing: content-box;
  box-sizing: content-box;
  height: 0;
}

.markdown-body pre {
  overflow: auto;
}

.markdown-body code,
.markdown-body kbd,
.markdown-body pre,
.markdown-body samp {
  font-family: monospace, monospace;
  font-size: 1em;
}

.markdown-body input {
  color: inherit;
  font: inherit;
  margin: 0;
}

.markdown-body html input[disabled] {
  cursor: default;
}

.markdown-body input {
  line-height: normal;
}

.markdown-body input[type="checkbox"] {
  box-sizing: border-box;
  padding: 0;
}

.markdown-body table {
  border-collapse: collapse;
  border-spacing: 0;
}

.markdown-body td,
.markdown-body th {
  padding: 0;
}

.markdown-body .codehilitetable {
  border: 0;
  border-spacing: 0;
}

.markdown-body .codehilitetable tr {
  border: 0;
}

.markdown-body .codehilitetable pre,
.markdown-body .codehilitetable div.codehilite {
  margin: 0;
}

.markdown-body .linenos,
.markdown-body .code,
.markdown-body .codehilitetable td {
  border: 0;
  padding: 0;
}

.markdown-body td:not(.linenos) .linenodiv {
  padding: 0 !important;
}

.markdown-body .code {
  width: 100%;
}

.markdown-body .linenos div pre,
.markdown-body .linenodiv pre,
.markdown-body .linenodiv {
  border: 0;
  -webkit-border-radius: 0;
  -moz-border-radius: 0;
  border-radius: 0;
  -webkit-border-top-left-radius: 3px;
  -webkit-border-bottom-left-radius: 3px;
  -moz-border-radius-topleft: 3px;
  -moz-border-radius-bottomleft: 3px;
  border-top-left-radius: 3px;
  border-bottom-left-radius: 3px;
}

.markdown-body .code div pre,
.markdown-body .code div {
  border: 0;
  -webkit-border-radius: 0;
  -moz-border-radius: 0;
  border-radius: 0;
  -webkit-border-top-right-radius: 3px;
  -webkit-border-bottom-right-radius: 3px;
  -moz-border-radius-topright: 3px;
  -moz-border-radius-bottomright: 3px;
  border-top-right-radius: 3px;
  border-bottom-right-radius: 3px;
}

.markdown-body * {
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

.markdown-body input {
  font: 13px Helvetica, arial, freesans, clean, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol";
  line-height: 1.4;
}

.markdown-body a {
  color: #4183c4;
  text-decoration: none;
}

.markdown-body a:hover,
.markdown-body a:focus,
.markdown-body a:active {
  text-decoration: underline;
}

.markdown-body hr {
  height: 0;
  margin: 15px 0;
  overflow: hidden;
  background: transparent;
  border: 0;
  border-bottom: 1px solid #ddd;
}

.markdown-body hr:before,
.markdown-body hr:after {
  display: table;
  content: " ";
}

.markdown-body hr:after {
  clear: both;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin-top: 15px;
  margin-bottom: 15px;
  line-height: 1.1;
}

.markdown-body h1 {
  font-size: 30px;
}

.markdown-body h2 {
  font-size: 21px;
}

.markdown-body h3 {
  font-size: 16px;
}

.markdown-body h4 {
  font-size: 14px;
}

.markdown-body h5 {
  font-size: 12px;
}

.markdown-body h6 {
  font-size: 11px;
}

.markdown-body blockquote {
  margin: 0;
}

.markdown-body ul,
.markdown-body ol {
  padding: 0;
  margin-top: 0;
  margin-bottom: 0;
}

.markdown-body ol ol,
.markdown-body ul ol {
  list-style-type: lower-roman;
}

.markdown-body ul ul ol,
.markdown-body ul ol ol,
.markdown-body ol ul ol,
.markdown-body ol ol ol {
  list-style-type: lower-alpha;
}

.markdown-body dd {
  margin-left: 0;
}

.markdown-body code,
.markdown-body pre,
.markdown-body samp {
  font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
  font-size: 12px;
}

.markdown-body pre {
  margin-top: 0;
  margin-bottom: 0;
}

.markdown-body kbd {
  background-color: #e7e7e7;
  background-image: -moz-linear-gradient(#fefefe, #e7e7e7);
  background-image: -webkit-linear-gradient(#fefefe, #e7e7e7);
  background-image: linear-gradient(#fefefe, #e7e7e7);
  background-repeat: repeat-x;
  border-radius: 2px;
  border: 1px solid #cfcfcf;
  color: #000;
  padding: 3px 5px;
  line-height: 10px;
  font: 11px Consolas, "Liberation Mono", Menlo, Courier, monospace;
  display: inline-block;
}

.markdown-body>*:first-child {
  margin-top: 0 !important;
}

.markdown-body>*:last-child {
  margin-bottom: 0 !important;
}

.markdown-body .headerlink {
  font: normal 400 16px fontawesome-mini;
  vertical-align: middle;
  margin-left: -16px;
  float: left;
  display: inline-block;
  text-decoration: none;
  opacity: 0;
  color: #333;
}

.markdown-body .headerlink:focus {
  outline: none;
}

.markdown-body h1 .headerlink {
  margin-top: 0.8rem;
}

.markdown-body h2 .headerlink,
.markdown-body h3 .headerlink {
  margin-top: 0.6rem;
}

.markdown-body h4 .headerlink {
  margin-top: 0.2rem;
}

.markdown-body h5 .headerlink,
.markdown-body h6 .headerlink {
  margin-top: 0;
}

.markdown-body .headerlink:hover,
.markdown-body h1:hover .headerlink,
.markdown-body h2:hover .headerlink,
.markdown-body h3:hover .headerlink,
.markdown-body h4:hover .headerlink,
.markdown-body h5:hover .headerlink,
.markdown-body h6:hover .headerlink {
  opacity: 1;
  text-decoration: none;
}

.markdown-body h1 {
  padding-bottom: 0.3em;
  font-size: 2.25em;
  line-height: 1.2;
  border-bottom: 1px solid #eee;
}

.markdown-body h2 {
  padding-bottom: 0.3em;
  font-size: 1.75em;
  line-height: 1.225;
  border-bottom: 1px solid #eee;
}

.markdown-body h3 {
  font-size: 1.5em;
  line-height: 1.43;
}

.markdown-body h4 {
  font-size: 1.25em;
}

.markdown-body h5 {
  font-size: 1em;
}

.markdown-body h6 {
  font-size: 1em;
  color: #777;
}

.markdown-body p,
.markdown-body blockquote,
.markdown-body ul,
.markdown-body ol,
.markdown-body dl,
.markdown-body table,
.markdown-body pre,
.markdown-body .admonition {
  margin-top: 0;
  margin-bottom: 16px;
}

.markdown-body hr {
  height: 4px;
  padding: 0;
  margin: 16px 0;
  background-color: #e7e7e7;
  border: 0 none;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 2em;
}

.markdown-body ul ul,
.markdown-body ul ol,
.markdown-body ol ol,
.markdown-body ol ul {
  margin-top: 0;
  margin-bottom: 0;
}

.markdown-body li>p {
  margin-top: 16px;
}

.markdown-body dl {
  padding: 0;
}

.markdown-body dl dt {
  padding: 0;
  margin-top: 16px;
  font-size: 1em;
  font-style: italic;
  font-weight: bold;
}

.markdown-body dl dd {
  padding: 0 16px;
  margin-bottom: 16px;
}

.markdown-body blockquote {
  padding: 0 15px;
  color: #777;
  border-left: 4px solid #ddd;
}

.markdown-body blockquote>:first-child {
  margin-top: 0;
}

.markdown-body blockquote>:last-child {
  margin-bottom: 0;
}

.markdown-body table {
  display: block;
  width: 100%;
  overflow: auto;
  word-break: normal;
  word-break: keep-all;
}

.markdown-body table th {
  font-weight: bold;
}

.markdown-body table th,
.markdown-body table td {
  padding: 6px 13px;
  border: 1px solid #ddd;
}

.markdown-body table tr {
  background-color: #fff;
  border-top: 1px solid #ccc;
}

.markdown-body table tr:nth-child(2n) {
  background-color: #f8f8f8;
}

.markdown-body img {
  max-width: 100%;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

.markdown-body code,
.markdown-body samp {
  padding: 0;
  padding-top: 0.2em;
  padding-bottom: 0.2em;
  margin: 0;
  font-size: 85%;
  background-color: rgba(0,0,0,0.04);
  border-radius: 3px;
}

.markdown-body code:before,
.markdown-body code:after {
  letter-spacing: -0.2em;
  content: "\00a0";
}

.markdown-body pre>code {
  padding: 0;
  margin: 0;
  font-size: 100%;
  word-break: normal;
  white-space: pre;
  background: transparent;
  border: 0;
}

.markdown-body .codehilite {
  margin-bottom: 16px;
}

.markdown-body .codehilite pre,
.markdown-body pre {
  padding: 16px;
  overflow: auto;
  font-size: 85%;
  line-height: 1.45;
  background-color: #f7f7f7;
  border-radius: 3px;
}

.markdown-body .codehilite pre {
  margin-bottom: 0;
  word-break: normal;
}

.markdown-body pre {
  word-wrap: normal;
}

.markdown-body pre code {
  display: inline;
  max-width: initial;
  padding: 0;
  margin: 0;
  overflow: initial;
  line-height: inherit;
  word-wrap: normal;
  background-color: transparent;
  border: 0;
}

.markdown-body pre code:before,
.markdown-body pre code:after {
  content: normal;
}

/* Admonition */
.markdown-body .admonition {
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  position: relative;
  border-radius: 3px;
  border: 1px solid #e0e0e0;
  border-left: 6px solid #333;
  padding: 10px 10px 10px 30px;
}

.markdown-body .admonition table {
  color: #333;
}

.markdown-body .admonition p {
  padding: 0;
}

.markdown-body .admonition-title {
  font-weight: bold;
  margin: 0;
}

.markdown-body .admonition>.admonition-title {
  color: #333;
}

.markdown-body .attention>.admonition-title {
  color: #a6d796;
}

.markdown-body .caution>.admonition-title {
  color: #d7a796;
}

.markdown-body .hint>.admonition-title {
  color: #96c6d7;
}

.markdown-body .danger>.admonition-title {
  color: #c25f77;
}

.markdown-body .question>.admonition-title {
  color: #96a6d7;
}

.markdown-body .note>.admonition-title {
  color: #d7c896;
}

.markdown-body .admonition:before,
.markdown-body .attention:before,
.markdown-body .caution:before,
.markdown-body .hint:before,
.markdown-body .danger:before,
.markdown-body .question:before,
.markdown-body .note:before {
  font: normal normal 16px fontawesome-mini;
  -moz-osx-font-smoothing: grayscale;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  line-height: 1.5;
  color: #333;
  position: absolute;
  left: 0;
  top: 0;
  padding-top: 10px;
  padding-left: 10px;
}

.markdown-body .admonition:before {
  content: "\f056\00a0";
  color: 333;
}

.markdown-body .attention:before {
  content: "\f058\00a0";
  color: #a6d796;
}

.markdown-body .caution:before {
  content: "\f06a\00a0";
  color: #d7a796;
}

.markdown-body .hint:before {
  content: "\f05a\00a0";
  color: #96c6d7;
}

.markdown-body .danger:before {
  content: "\f057\00a0";
  color: #c25f77;
}

.markdown-body .question:before {
  content: "\f059\00a0";
  color: #96a6d7;
}

.markdown-body .note:before {
  content: "\f040\00a0";
  color: #d7c896;
}

.markdown-body .admonition::after {
  content: normal;
}

.markdown-body .attention {
  border-left: 6px solid #a6d796;
}

.markdown-body .caution {
  border-left: 6px solid #d7a796;
}

.markdown-body .hint {
  border-left: 6px solid #96c6d7;
}

.markdown-body .danger {
  border-left: 6px solid #c25f77;
}

.markdown-body .question {
  border-left: 6px solid #96a6d7;
}

.markdown-body .note {
  border-left: 6px solid #d7c896;
}

.markdown-body .admonition>*:first-child {
  margin-top: 0 !important;
}

.markdown-body .admonition>*:last-child {
  margin-bottom: 0 !important;
}

/* progress bar*/
.markdown-body .progress {
  display: block;
  width: 300px;
  margin: 10px 0;
  height: 24px;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  border-radius: 3px;
  background-color: #ededed;
  position: relative;
  box-shadow: inset -1px 1px 3px rgba(0, 0, 0, .1);
}

.markdown-body .progress-label {
  position: absolute;
  text-align: center;
  font-weight: bold;
  width: 100%; margin: 0;
  line-height: 24px;
  color: #333;
  text-shadow: 1px 1px 0 #fefefe, -1px -1px 0 #fefefe, -1px 1px 0 #fefefe, 1px -1px 0 #fefefe, 0 1px 0 #fefefe, 0 -1px 0 #fefefe, 1px 0 0 #fefefe, -1px 0 0 #fefefe, 1px 1px 2px #000;
  -webkit-font-smoothing: antialiased !important;
  white-space: nowrap;
  overflow: hidden;
}

.markdown-body .progress-bar {
  height: 24px;
  float: left;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  border-radius: 3px;
  background-color: #96c6d7;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), inset 0 -1px 0 rgba(0, 0, 0, .1);
  background-size: 30px 30px;
  background-image: -webkit-linear-gradient(
    135deg, rgba(255, 255, 255, .4) 27%,
    transparent 27%,
    transparent 52%, rgba(255, 255, 255, .4) 52%,
    rgba(255, 255, 255, .4) 77%,
    transparent 77%, transparent
  );
  background-image: -moz-linear-gradient(
    135deg,
    rgba(255, 255, 255, .4) 27%, transparent 27%,
    transparent 52%, rgba(255, 255, 255, .4) 52%,
    rgba(255, 255, 255, .4) 77%, transparent 77%,
    transparent
  );
  background-image: -ms-linear-gradient(
    135deg,
    rgba(255, 255, 255, .4) 27%, transparent 27%,
    transparent 52%, rgba(255, 255, 255, .4) 52%,
    rgba(255, 255, 255, .4) 77%, transparent 77%,
    transparent
  );
  background-image: -o-linear-gradient(
    135deg,
    rgba(255, 255, 255, .4) 27%, transparent 27%,
    transparent 52%, rgba(255, 255, 255, .4) 52%,
    rgba(255, 255, 255, .4) 77%, transparent 77%,
    transparent
  );
  background-image: linear-gradient(
    135deg,
    rgba(255, 255, 255, .4) 27%, transparent 27%,
    transparent 52%, rgba(255, 255, 255, .4) 52%,
    rgba(255, 255, 255, .4) 77%, transparent 77%,
    transparent
  );
}

.markdown-body .progress-100plus .progress-bar {
  background-color: #a6d796;
}

.markdown-body .progress-80plus .progress-bar {
  background-color: #c6d796;
}

.markdown-body .progress-60plus .progress-bar {
  background-color: #d7c896;
}

.markdown-body .progress-40plus .progress-bar {
  background-color: #d7a796;
}

.markdown-body .progress-20plus .progress-bar {
  background-color: #d796a6;
}

.markdown-body .progress-0plus .progress-bar {
  background-color: #c25f77;
}

.markdown-body .candystripe-animate .progress-bar{
  -webkit-animation: animate-stripes 3s linear infinite;
  -moz-animation: animate-stripes 3s linear infinite;
  animation: animate-stripes 3s linear infinite;
}

@-webkit-keyframes animate-stripes {
  0% {
    background-position: 0 0;
  }

  100% {
    background-position: 60px 0;
  }
}

@-moz-keyframes animate-stripes {
  0% {
    background-position: 0 0;
  }

  100% {
    background-position: 60px 0;
  }
}

@keyframes animate-stripes {
  0% {
    background-position: 0 0;
  }

  100% {
    background-position: 60px 0;
  }
}

.markdown-body .gloss .progress-bar {
  box-shadow:
    inset 0 4px 12px rgba(255, 255, 255, .7),
    inset 0 -12px 0 rgba(0, 0, 0, .05);
}

/* Multimarkdown Critic Blocks */
.markdown-body .critic_mark {
  background: #ff0;
}

.markdown-body .critic_delete {
  color: #c82829;
  text-decoration: line-through;
}

.markdown-body .critic_insert {
  color: #718c00 ;
  text-decoration: underline;
}

.markdown-body .critic_comment {
  color: #8e908c;
  font-style: italic;
}

.markdown-body .headeranchor {
  font: normal normal 16px fontawesome-mini;
  line-height: 1;
  display: inline-block;
  text-decoration: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.headeranchor:before {
  content: '\e157';
}

.markdown-body .task-list-item {
  list-style-type: none;
}

.markdown-body .task-list-item+.task-list-item {
  margin-top: 3px;
}

.markdown-body .task-list-item input {
  margin: 0 4px 0.25em -20px;
  vertical-align: middle;
}

/* Media */
@media only screen and (min-width: 480px) {
  .markdown-body {
    font-size:14px;
  }
}

@media only screen and (min-width: 768px) {
  .markdown-body {
    font-size:16px;
  }
}

@media print {
  .markdown-body * {
    background: transparent !important;
    color: black !important;
    filter:none !important;
    -ms-filter: none !important;
  }

  .markdown-body {
    font-size:12pt;
    max-width:100%;
    outline:none;
    border: 0;
  }

  .markdown-body a,
  .markdown-body a:visited {
    text-decoration: underline;
  }

  .markdown-body .headeranchor-link {
    display: none;
  }

  .markdown-body a[href]:after {
    content: " (" attr(href) ")";
  }

  .markdown-body abbr[title]:after {
    content: " (" attr(title) ")";
  }

  .markdown-body .ir a:after,
  .markdown-body a[href^="javascript:"]:after,
  .markdown-body a[href^="#"]:after {
    content: "";
  }

  .markdown-body pre {
    white-space: pre;
    white-space: pre-wrap;
    word-wrap: break-word;
  }

  .markdown-body pre,
  .markdown-body blockquote {
    border: 1px solid #999;
    padding-right: 1em;
    page-break-inside: avoid;
  }

  .markdown-body .progress,
  .markdown-body .progress-bar {
    -moz-box-shadow: none;
    -webkit-box-shadow: none;
    box-shadow: none;
  }

  .markdown-body .progress {
    border: 1px solid #ddd;
  }

  .markdown-body .progress-bar {
    height: 22px;
    border-right: 1px solid #ddd;
  }

  .markdown-body tr,
  .markdown-body img {
    page-break-inside: avoid;
  }

  .markdown-body img {
    max-width: 100% !important;
  }

  .markdown-body p,
  .markdown-body h2,
  .markdown-body h3 {
    orphans: 3;
    widows: 3;
  }

  .markdown-body h2,
  .markdown-body h3 {
    page-break-after: avoid;
  }
}
</style><style>/*github*/
.codehilite {background-color:#fff;color:#333333;}
.codehilite .hll {background-color:#ffffcc;}
.codehilite .c{color:#999988;font-style:italic}
.codehilite .err{color:#a61717;background-color:#e3d2d2}
.codehilite .k{font-weight:bold}
.codehilite .o{font-weight:bold}
.codehilite .cm{color:#999988;font-style:italic}
.codehilite .cp{color:#999999;font-weight:bold}
.codehilite .c1{color:#999988;font-style:italic}
.codehilite .cs{color:#999999;font-weight:bold;font-style:italic}
.codehilite .gd{color:#000000;background-color:#ffdddd}
.codehilite .ge{font-style:italic}
.codehilite .gr{color:#aa0000}
.codehilite .gh{color:#999999}
.codehilite .gi{color:#000000;background-color:#ddffdd}
.codehilite .go{color:#888888}
.codehilite .gp{color:#555555}
.codehilite .gs{font-weight:bold}
.codehilite .gu{color:#800080;font-weight:bold}
.codehilite .gt{color:#aa0000}
.codehilite .kc{font-weight:bold}
.codehilite .kd{font-weight:bold}
.codehilite .kn{font-weight:bold}
.codehilite .kp{font-weight:bold}
.codehilite .kr{font-weight:bold}
.codehilite .kt{color:#445588;font-weight:bold}
.codehilite .m{color:#009999}
.codehilite .s{color:#dd1144}
.codehilite .n{color:#333333}
.codehilite .na{color:teal}
.codehilite .nb{color:#0086b3}
.codehilite .nc{color:#445588;font-weight:bold}
.codehilite .no{color:teal}
.codehilite .ni{color:purple}
.codehilite .ne{color:#990000;font-weight:bold}
.codehilite .nf{color:#990000;font-weight:bold}
.codehilite .nn{color:#555555}
.codehilite .nt{color:navy}
.codehilite .nv{color:teal}
.codehilite .ow{font-weight:bold}
.codehilite .w{color:#bbbbbb}
.codehilite .mf{color:#009999}
.codehilite .mh{color:#009999}
.codehilite .mi{color:#009999}
.codehilite .mo{color:#009999}
.codehilite .sb{color:#dd1144}
.codehilite .sc{color:#dd1144}
.codehilite .sd{color:#dd1144}
.codehilite .s2{color:#dd1144}
.codehilite .se{color:#dd1144}
.codehilite .sh{color:#dd1144}
.codehilite .si{color:#dd1144}
.codehilite .sx{color:#dd1144}
.codehilite .sr{color:#009926}
.codehilite .s1{color:#dd1144}
.codehilite .ss{color:#990073}
.codehilite .bp{color:#999999}
.codehilite .vc{color:teal}
.codehilite .vg{color:teal}
.codehilite .vi{color:teal}
.codehilite .il{color:#009999}
.codehilite .gc{color:#999;background-color:#EAF2F5}
</style><title>Keepalived</title></head><body><article class="markdown-body"><h1 id="linuxkeepalived"><a href="https://www.jianshu.com/p/b050d8861fc1">Linux高可用之Keepalived</a><a class="headerlink" href="#linuxkeepalived" title="Permanent link"></a></h1>
<h2 id="_1">简介<a class="headerlink" href="#_1" title="Permanent link"></a></h2>
<p>Keepalived是基于<strong>vrrp协议</strong>的一款高可用软件。Keepailived有一台主服务器和多台备份服务器，在主服务器和备份服务器上面部署相同的
服务配置，使用一个<strong>虚拟IP地址</strong>对外提供服务，当主服务器出现故障时，虚拟IP地址会自动漂移到备份服务器。</p>
<dl>
<dt>VRRP</dt>
<dd>虚拟路由器冗余协议(Virtual Router Redundancy Protocol)，VRRP是为了解决<strong>静态路由</strong>的高可用。</dd>
<dt>VRRP的基本架构</dt>
<dd>虚拟路由器由多个路由器组成，每个路由器都有各自的IP和共同的VRID(0-255)，其中一个VRRP路由器通过<strong>竞选</strong>成为MASTER，占有VIP，
对外提供路由服务，其他成为BACKUP，MASTER以<strong>IP组播(组播地址：224.0.0.18)</strong>形式发送VRRP协议包，与BACKUP保持心跳连接，若MASTER
不可用（或BACKUP接收不到VRRP协议包），则BACKUP通过竞选产生新的MASTER并继续对外提供路由服务，从而实现高可用。</dd>
<dt>vrrp协议的相关术语</dt>
<dd>
<ul>
<li>虚拟路由器：Virtual Router </li>
<li>虚拟路由器标识：VRID(0-255)</li>
<li>物理路由器：<ul>
<li>master  ：主设备</li>
<li>backup  ：备用设备</li>
<li>priority：优先级</li>
</ul>
</li>
<li>VIP：Virtual IP </li>
<li>VMAC：Virutal MAC (00-00-5e-00-01-VRID)</li>
<li>GraciousARP</li>
</ul>
</dd>
<dt>安全认证</dt>
<dd>简单字符认证、HMAC机制，只对信息做认证, MD5（leepalived不支持）</dd>
<dt>工作模式</dt>
<dd>主/备：单虚拟路径器；
主/主：主/备（虚拟路径器），备/主（虚拟路径器）</dd>
<dt>工作类型</dt>
<dd>抢占式：当出现比现有主服务器优先级高的服务器时，会发送通告抢占角色成为主服务器
非抢占式：主从都需配置nopreempt</dd>
</dl>
<h2 id="keepalived">keepalived<a class="headerlink" href="#keepalived" title="Permanent link"></a></h2>
<h3 id="_2">核心组件<a class="headerlink" href="#_2" title="Permanent link"></a></h3>
<dl>
<dd>
<ul>
<li>vrrp stack：vrrp协议的实现</li>
<li>ipvs wrapper：为集群内的所有节点生成IPVS规则</li>
<li>checkers：对IPVS集群的各RS做健康状态检测</li>
<li>控制组件：配置文件分析器，用来实现配置文件的分析和加载</li>
<li>IO复用器</li>
<li>内存管理组件，用来管理keepalived高可用是的内存管理</li>
</ul>
</dd>
<dt>注意</dt>
<dd>各节点时间必须同步,确保各节点的用于集群服务的接口支持<strong>MULTICAST通信</strong>（组播）；</dd>
</dl>
<h3 id="_3">安装<a class="headerlink" href="#_3" title="Permanent link"></a></h3>
<p>从CentOS 6.4开始keepalived随系统base仓库提供，可以使用<code>yum -y install keepalived</code>安装。</p>
<dl>
<dt>配置文件</dt>
<dd>
<ul>
<li>主配置文件：/etc/keepalived/keepalived.conf</li>
<li>主程序文件：/usr/sbin/keepalived</li>
<li>提供校验码：/usr/bin/genhash</li>
<li>Unit File：keepalived.service</li>
<li>Unit File的环境配置文件：/etc/sysconfig/keepalived</li>
</ul>
</dd>
</dl>
<h3 id="_4">配置<a class="headerlink" href="#_4" title="Permanent link"></a></h3>
<p>主配置文件详解</p>
<div class="codehilite"><pre>! Configuration File <span class="k">for</span> keepalived

global_defs <span class="o">{</span>
   notification_email <span class="o">{</span>   <span class="c1">#发送报警邮件收件地址</span>
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   <span class="o">}</span>
   notification_email_from Alexandre.Cassen@firewall.loc   <span class="c1">#指明报警邮件的发送地址</span>
   smtp_server 192.168.200.1    <span class="c1">#邮件服务器地址</span>
   smtp_connect_timeout <span class="m">30</span>      <span class="c1">#smtp的超时时间</span>
   router_id LVS_DEVEL          <span class="c1">#物理服务器的主机名</span>
   vrrp_mcast_group4            <span class="c1">#定义一个组播地址</span>
   static_ipaddress
        <span class="o">{</span>
        192.168.1.1/24 dev eth0 scope global
        <span class="o">}</span>
        static_routes
        <span class="o">{</span>
        192.168.2.0/24 via 192.168.1.100 dev eth0
        <span class="o">}</span>

<span class="o">}</span>
    vrrp_sync_group VG_1 <span class="o">{</span>              <span class="c1">#定义一个故障组，组内有一个虚拟路由出现故障另一个也会一起跟着转移，适用于LVS的NAT模型。</span>
        group <span class="o">{</span>
            VI1     <span class="c1"># name of vrrp_instance (below)         </span>
            VI2     <span class="c1"># One for each moveable IP</span>

             <span class="o">}</span>
    <span class="o">}</span>


vrrp_instance VI_1 <span class="o">{</span>        <span class="c1">#定义一个虚拟路由</span>
    state MASTER<span class="p">|</span>BACKUP     <span class="c1">#当前节点在此虚拟路由器上的初始状态；只能有一个是MASTER，余下的都应该为BACKUP；</span>
    interface eth0          <span class="c1">#绑定为当前虚拟路由器使用的物理接口；</span>
    virtual_router_id <span class="m">51</span>    <span class="c1">#当前虚拟路由器的惟一标识，范围是0-255；</span>
    priority <span class="m">100</span>            <span class="c1">#当前主机在此虚拟路径器中的优先级；范围1-254；</span>
    advert_int <span class="m">1</span>            <span class="c1">#通告发送间隔，包含主机优先级、心跳等。</span>
    authentication <span class="o">{</span>        <span class="c1">#认证配置   </span>
        auth_type PASS      <span class="c1">#认证类型，PASS表示简单字符串认证</span>
        auth_pass <span class="m">1111</span>      <span class="c1">#密码,PASS密码最长为8位</span>

   virtual_ipaddress <span class="o">{</span>
    192.168.200.16          <span class="c1">#虚拟路由IP地址，以辅助地址方式设置</span>
    192.168.200.18/24 dev eth2 label eth2:1 <span class="c1">#以别名的方式设置</span>
    <span class="o">}</span>

track_interface <span class="o">{</span>
        eth0
        eth1

<span class="o">}</span>                           <span class="c1">#配置要监控的网络接口，一旦接口出现故障，则转为FAULT状态；</span>
nopreempt                   <span class="c1">#定义工作模式为非抢占模式；</span>
preempt_delay <span class="m">300</span>           <span class="c1">#抢占式模式下，节点上线后触发新选举操作的延迟时长；</span>
   virtual_routes <span class="o">{</span>         <span class="c1">#配置路由信息，可选项</span>
               <span class="c1">#  src &lt;IPADDR&gt; [to] &lt;IPADDR&gt;/&lt;MASK&gt; via|gw &lt;IPADDR&gt; [or &lt;IPADDR&gt;] dev &lt;STRING&gt; scope</span>
       &lt;SCOPE&gt; tab
               src 192.168.100.1 to 192.168.109.0/24 via 192.168.200.254 dev eth1
               192.168.112.0/24 via 192.168.100.254       192.168.113.0/24  via  192.168.200.254  or 192.168.100.254 dev eth1      blackhole 192.168.114.0/24
           <span class="o">}</span>


    notify_master &lt;STRING&gt;<span class="p">|</span>&lt;QUOTED-STRING&gt;       <span class="c1">#当前节点成为主节点时触发的脚本。</span>
    notify_backup &lt;STRING&gt;<span class="p">|</span>&lt;QUOTED-STRING&gt;       <span class="c1">#当前节点转为备节点时触发的脚本。</span>
    notify_fault &lt;STRING&gt;<span class="p">|</span>&lt;QUOTED-STRING&gt;        <span class="c1">#当前节点转为“失败”状态时触发的脚本。</span>
    notify &lt;STRING&gt;<span class="p">|</span>&lt;QUOTED-STRING&gt;              <span class="c1">#通用格式的通知触发机制，一个脚本可完成以上三种状态的转换时的通知。</span>
    smtp_alert                                   <span class="c1">#如果加入这个选项，将调用前面设置的邮件设置，并自动根据状态发送信息 </span>
<span class="o">}</span>
virtual_server 192.168.200.100 <span class="m">443</span> <span class="o">{</span>    <span class="c1">#LVS配置段 ，设置LVS的VIP地址和端口</span>
    delay_loop                          <span class="c1">#服务轮询的时间间隔；检测RS服务器的状态。</span>
    lb_algo rr                          <span class="c1">#调度算法，可选rr|wrr|lc|wlc|lblc|sh|dh。</span>
    lb_kind NAT                         <span class="c1">#集群类型。</span>
    nat_mask 255.255.255.0              <span class="c1">#子网掩码，可选项。</span>
    persistence_timeout <span class="m">50</span>              <span class="c1">#是否启用持久连接，连接保存时长</span>
    protocol TCP                        <span class="c1">#协议，只支持TCP</span>
    sorry_server &lt;IPADDR&gt; &lt;PORT&gt;        <span class="c1">#备用服务器地址，可选项。</span>

    real_server 192.168.201.100 <span class="m">443</span> <span class="o">{</span>   <span class="c1">#配置RS服务器的地址和端口</span>
        weight <span class="m">1</span>                        <span class="c1">#权重</span>
     SSL_GET <span class="o">{</span>                          <span class="c1">#检测RS服务器的状态，发送请求报文</span>
            url <span class="o">{</span>
              path /                    <span class="c1">#请求的URL</span>
              digest ff20ad2481f97b1754ef3e12ecd3a9cc  <span class="c1">#对请求的页面进行hash运算，然后和这个hash码进行比对，如果hash码一样就表示状态正常</span>
              status_code &lt;INT&gt;         <span class="c1">#判断上述检测机制为健康状态的响应码,和digest二选一即可。</span>

            <span class="o">}</span>                           <span class="c1">#这个hash码可以使用genhash命令请求这个页面生成</span>
            connect_timeout <span class="m">3</span>           <span class="c1">#连接超时时间</span>
            nb_get_retry <span class="m">3</span>              <span class="c1">#超时重试次数</span>
            delay_before_retry <span class="m">3</span>        <span class="c1">#每次超时过后多久再进行连接</span>
            connect_ip &lt;IP ADDRESS&gt;     <span class="c1">#向当前RS的哪个IP地址发起健康状态检测请求</span>
            connect_port &lt;PORT&gt;         <span class="c1">#向当前RS的哪个PORT发起健康状态检测请求</span>
            bindto &lt;IP ADDRESS&gt;         <span class="c1">#发出健康状态检测请求时使用的源地址；</span>
            bind_port &lt;PORT&gt;            <span class="c1">#发出健康状态检测请求时使用的源端口；</span>
        <span class="o">}</span>
    <span class="o">}</span>
<span class="o">}</span>
</pre></div>

<h3 id="_5">健康状态检测机制<a class="headerlink" href="#_5" title="Permanent link"></a></h3>
<dl>
<dd>
<ul>
<li>HTTP_GET</li>
<li>SSL_GET</li>
<li>TCP_CHECK</li>
<li>SMTP_CHECK</li>
<li>MISS_CHECK #调用自定义脚本进行检测</li>
</ul>
</dd>
</dl>
<div class="codehilite"><pre>TCP_CHECK <span class="o">{</span>
        connect_ip &lt;IP ADDRESS&gt;         <span class="c1">#向当前RS的哪个IP地址发起健康状态检测请求;</span>
        connect_port &lt;PORT&gt;             <span class="c1">#向当前RS的哪个PORT发起健康状态检测请求;</span>
        bindto &lt;IP ADDRESS&gt;             <span class="c1">#发出健康状态检测请求时使用的源地址；</span>
        bind_port &lt;PORT&gt;                <span class="c1">#发出健康状态检测请求时使用的源端口；</span>
        connect_timeout &lt;INTEGER&gt;       <span class="c1">#连接请求的超时时长；</span>
<span class="o">}</span>
</pre></div>

<h2 id="lvs">实现LVS高可用集群<a class="headerlink" href="#lvs" title="Permanent link"></a></h2>
<p>实验主机
虚拟IP:192.168.166.100</p>
<dl>
<dt>2台CentOS 7.3</dt>
<dd>CentOS 7.3   主服务器，  IP：192.168.166.130
CentOS 7.3-1 备份服务器，IP：192.168.166.132</dd>
<dt>2台CentOS 6.9</dt>
<dd>CentOS 6.9  IP：192.168.166.129
CentOS6.9-1 IP：192.168.166.131</dd>
</dl>
<p>注：在配置服务前需要注意几台主机的<strong>防火墙策略</strong>，和<strong>SELinux</strong>配置。</p>
<p>主调度器配置
<div class="codehilite"><pre><span class="o">[</span>root@CentOS7.3 ~<span class="o">]</span><span class="c1">#yum -y install keepalived ipvsadm        #安装keepalived和LVS管理软件ipvsadm</span>
<span class="o">[</span>root@CentOS7.3 ~<span class="o">]</span><span class="c1">#vim /etc/keepalived/keepalived.conf  #配置keepalived</span>
! Configuration File <span class="k">for</span> keepalived

global_defs <span class="o">{</span>
   notification_email <span class="o">{</span>
   root@localhost
   <span class="o">}</span>
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1                    <span class="c1">#邮件服务器的地址</span>
   smtp_connect_timeout 30
   router_id CentOS7.3                      <span class="c1">#主调度器的主机名</span>
   vrrp_mcast_group4 224.26.1.1             <span class="c1">#发送心跳信息的组播地址</span>

<span class="o">}</span>

vrrp_instance VI_1 <span class="o">{</span>
    state MASTER                            <span class="c1">#主调度器的初始角色</span>
    interface eth0                          <span class="c1">#虚拟IP工作的网卡接口</span>
    virtual_router_id <span class="m">66</span>                    <span class="c1">#虚拟路由的ID</span>
    priority <span class="m">100</span>                            <span class="c1">#主调度器的选举优先级</span>
    advert_int 1
    authentication <span class="o">{</span>
        auth_type PASS                      <span class="c1">#集群主机的认证方式</span>
        auth_pass <span class="m">123456</span>                    <span class="c1">#密钥,最长8位</span>
    <span class="o">}</span>
    virtual_ipaddress <span class="o">{</span>
        192.168.166.100                     <span class="c1">#虚拟IP</span>
    <span class="o">}</span>
<span class="o">}</span>

virtual_server 192.168.166.100 <span class="m">80</span> <span class="o">{</span>         <span class="c1">#LVS配置段，VIP</span>
    delay_loop 6
    lb_algo rr                              <span class="c1">#调度算法轮询</span>
    lb_kind DR                              <span class="c1">#工作模式DR</span>
    nat_mask 255.255.255.0
<span class="c1">#    persistence_timeout 50                  #持久连接，在测试时需要注释，否则会在设置的时间内把请求都调度到一台RS服务器上面</span>
    protocol TCP
    sorry_server 127.0.0.1 <span class="m">80</span>               <span class="c1">#Sorry server的服务器地址及端口</span>
<span class="c1">#Sorry server就是在后端的服务器全部宕机的情况下紧急提供服务。</span>
    real_server 192.168.166.129 <span class="m">80</span> <span class="o">{</span>        <span class="c1">#RS服务器地址和端口</span>
        weight <span class="m">1</span>                            <span class="c1">#RS的权重</span>
        HTTP_GET <span class="o">{</span>                          <span class="c1">#健康状态检测方法</span>
            url <span class="o">{</span>
              path /
              status_code <span class="m">200</span>               <span class="c1">#状态判定规则</span>
            <span class="o">}</span>
            connect_timeout 1
            nb_get_retry 3
            delay_before_retry 1
        <span class="o">}</span>
    <span class="o">}</span>

    real_server 192.168.166.131 <span class="m">80</span> <span class="o">{</span>
        weight 1
        HTTP_GET <span class="o">{</span>
            url <span class="o">{</span>
              path /
                status_code 200
            <span class="o">}</span>
            connect_timeout 1
            nb_get_retry 3
            delay_before_retry 1
        <span class="o">}</span>
    <span class="o">}</span>
<span class="o">}</span>

<span class="o">[</span>root@CentOS7.3 keepalived<span class="o">]</span><span class="c1">#systemctl start keepalived          #启动keepalived</span>
<span class="o">[</span>root@CentOS7.3 keepalived<span class="o">]</span><span class="c1">#ip a l eth0                         #查看虚拟路由绑定的网卡    </span>
2: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu <span class="m">1500</span> qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:b9:7d:cb brd ff:ff:ff:ff:ff:ff
    inet 192.168.166.130/24 brd 192.168.166.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 192.168.166.100/32 scope global eth0                   <span class="c1">#虚拟IP已经绑定在了eth网卡上</span>
       valid_lft forever preferred_lft forever
    inet6 fe80::50fe:a3f3:83a0:d38a/64 scope link 
       valid_lft forever preferred_lft forever
</pre></div>
备份调度器的配置
<div class="codehilite"><pre><span class="o">[</span>root@centos7.3-1 ~<span class="o">]</span><span class="c1">#yum -y install keepalived ipvsadm </span>

! Configuration File <span class="k">for</span> keepalived

global_defs <span class="o">{</span>
   notification_email <span class="o">{</span>
   root@localhost
   <span class="o">}</span>
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id CentOS7.3-1                <span class="c1">#备份调度器的主机名</span>
   vrrp_mcast_group4 224.26.1.1         <span class="c1">#这个组播地址需与集群内的其他主机相同</span>

<span class="o">}</span>

vrrp_instance VI_1 <span class="o">{</span>
    state BACKUP                        <span class="c1">#初始角色，备份服务器需设置为BACKUP</span>
    interface eth0
    virtual_router_id <span class="m">66</span>                <span class="c1">#虚拟路由的ID一定要和集群内的其他主机相同</span>
    priority <span class="m">90</span>                         <span class="c1">#选举优先级，要比主调度器地一些</span>
    advert_int 1
    authentication <span class="o">{</span>
        auth_type PASS
        auth_pass <span class="m">123456</span>                <span class="c1">#密钥需要和集群内的主服务器相同</span>
    <span class="o">}</span>
    virtual_ipaddress <span class="o">{</span>
        192.168.166.100
    <span class="o">}</span>
<span class="o">}</span>
                <span class="c1">#余下配置和主服务器相同</span>
virtual_server 192.168.166.100 <span class="m">80</span> <span class="o">{</span>
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.0
<span class="c1">#    persistence_timeout 50              </span>
    protocol TCP
    sorry_server 127.0.0.1 80

    real_server 192.168.166.129 <span class="m">80</span> <span class="o">{</span>
        weight 1
        HTTP_GET <span class="o">{</span>
            url <span class="o">{</span>
              path /
              status_code 200
            <span class="o">}</span>
            connect_timeout 1
            nb_get_retry 3
            delay_before_retry 1
        <span class="o">}</span>
    <span class="o">}</span>

    real_server 192.168.166.131 <span class="m">80</span> <span class="o">{</span>
        weight 1
        HTTP_GET <span class="o">{</span>
            url <span class="o">{</span>
              path /
                status_code 200
            <span class="o">}</span>
            connect_timeout 1
            nb_get_retry 3
            delay_before_retry 1
        <span class="o">}</span>
    <span class="o">}</span>
<span class="o">}</span>
<span class="o">[</span>root@centos7.3-1 ~<span class="o">]</span><span class="c1">#systemctl start keepalived         #启动备份keepalived</span>
<span class="o">[</span>root@centos7.3-1 ~<span class="o">]</span><span class="c1">#ip a l eth0                        #查看虚拟路由绑定的网卡接口</span>
<span class="o">[</span>root@centos7.3-1 ~<span class="o">]</span><span class="c1">#ip a l eth0</span>
2: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu <span class="m">1500</span> qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:7e:ec:ef brd ff:ff:ff:ff:ff:ff
    inet 192.168.166.132/24 brd 192.168.166.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::9aab:52b3:cc1e:fbef/64 scope link 
       valid_lft forever preferred_lft forever
</pre></div></p>
<p>测试虚拟IP地址漂移</p>
<p>关闭主服务器的keepalived，并查看eth0接口</p>
<p><div class="codehilite"><pre>systemctl stop keepalived
ip a l eth0
</pre></div>
<img alt="测试虚拟IP地址漂移1" src="///F://workspace/gitee/LearningSummary/%E4%BA%91%E8%AE%A1%E7%AE%97%26%E9%9B%86%E7%BE%A4/images/%E6%B5%8B%E8%AF%95%E8%99%9A%E6%8B%9FIP%E5%9C%B0%E5%9D%80%E6%BC%82%E7%A7%BB1.png" /></p>
<p>查看备份服务器的eth0接口，地址已经漂移到了备份服务器上面
<code>ip a l eth0</code>
<img alt="测试虚拟IP地址漂移2" src="///F://workspace/gitee/LearningSummary/%E4%BA%91%E8%AE%A1%E7%AE%97%26%E9%9B%86%E7%BE%A4/images/%E6%B5%8B%E8%AF%95%E8%99%9A%E6%8B%9FIP%E5%9C%B0%E5%9D%80%E6%BC%82%E7%A7%BB2.png" /></p>
<p>可以看到上图提示有新邮件。使用mail命令查看邮件列表，都是后端服务器状态检测的邮件，说明配置的报警邮件生效了。应为后端服务器还没有
配置所以检测的状态全是down。
<img alt="邮件" src="///F://workspace/gitee/LearningSummary/%E4%BA%91%E8%AE%A1%E7%AE%97%26%E9%9B%86%E7%BE%A4/images/%E9%82%AE%E4%BB%B6.png" /></p>
<p>启动主服务器，地址又漂移回了主服务器
<img alt="漂移回了主服务器" src="///F://workspace/gitee/LearningSummary/%E4%BA%91%E8%AE%A1%E7%AE%97%26%E9%9B%86%E7%BE%A4/images/%E6%BC%82%E7%A7%BB%E5%9B%9E%E4%BA%86%E4%B8%BB%E6%9C%8D%E5%8A%A1%E5%99%A8.png" /></p>
<p>配置RS服务器</p>
<p>RS1配置
<div class="codehilite"><pre><span class="o">[</span>root@CentOS6.9 ~<span class="o">]</span><span class="c1">#yum -y install httpd                 #安装httpd服务</span>
<span class="o">[</span>root@CentOS6.9 ~<span class="o">]</span><span class="c1">#vim lvs.sh                           #创建一个配置脚本</span>
<span class="c1">#!/bin/bash</span>
<span class="nv">vip</span><span class="o">=</span>192.168.166.100                                     <span class="c1">#VIP地址</span>
<span class="nv">mask</span><span class="o">=</span>255.255.255.255                    
<span class="nv">dev</span><span class="o">=</span>eth0:1
<span class="k">case</span> <span class="nv">$1</span> in
start<span class="o">)</span>
        <span class="nb">echo </span><span class="m">1</span> &gt; /proc/sys/net/ipv4/conf/all/arp_ignore
        <span class="nb">echo </span><span class="m">1</span> &gt; /proc/sys/net/ipv4/conf/lo/arp_ignore
        <span class="nb">echo </span><span class="m">2</span> &gt; /proc/sys/net/ipv4/conf/all/arp_announce
        <span class="nb">echo </span><span class="m">2</span> &gt; /proc/sys/net/ipv4/conf/lo/arp_announce
        ifconfig <span class="nv">$dev</span> <span class="nv">$vip</span> netmask <span class="nv">$mask</span> broadcast <span class="nv">$vip</span> up
        route add -host <span class="nv">$vip</span> dev <span class="nv">$dev</span>
<span class="p">;;</span>
stop<span class="o">)</span>
        ifconfig <span class="nv">$dev</span> down
        <span class="nb">echo </span><span class="m">0</span> &gt; /proc/sys/net/ipv4/conf/all/arp_ignore
        <span class="nb">echo </span><span class="m">0</span> &gt; /proc/sys/net/ipv4/conf/lo/arp_ignore
        <span class="nb">echo </span><span class="m">0</span> &gt; /proc/sys/net/ipv4/conf/all/arp_announce
        <span class="nb">echo </span><span class="m">0</span> &gt; /proc/sys/net/ipv4/conf/lo/arp_announce
<span class="p">;;</span>
*<span class="o">)</span>
        <span class="nb">echo</span> <span class="s2">&quot;Usage: </span><span class="k">$(</span>basename <span class="nv">$0</span><span class="k">)</span><span class="s2"> start|stop&quot;</span>
        <span class="nb">exit </span>1
<span class="p">;;</span>
<span class="k">esac</span>

<span class="o">[</span>root@CentOS6.9 ~<span class="o">]</span><span class="c1">#bash lvs.sh start</span>
<span class="o">[</span>root@CentOS6.9 ~<span class="o">]</span><span class="c1">#ip a l eth0:0</span>
2: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu <span class="m">1500</span> qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:23:38:c9 brd ff:ff:ff:ff:ff:ff
    inet 192.168.166.129/24 brd 192.168.166.255 scope global eth0
    inet 192.168.166.100/32 brd 192.168.166.100 scope global eth0:1
    inet6 fe80::20c:29ff:fe23:38c9/64 scope link 
       valid_lft forever preferred_lft forever
<span class="o">[</span>root@CentOS6.9 ~<span class="o">]</span><span class="c1">#echo WebServer1 &gt; /var/www/html/index.html</span>
<span class="o">[</span>root@CentOS6.9 ~<span class="o">]</span><span class="c1">#cat /var/www/html/index.html </span>
WebServer1
<span class="o">[</span>root@CentOS6.9 ~<span class="o">]</span><span class="c1">#service httpd start</span>
</pre></div></p></article></body></html>